﻿
@{
    ViewBag.Title = "零售";
    Layout = "~/Views/Jxc/_Layout.cshtml";
}

<h2>@ViewBag.Title</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="form-horizontal">
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.Hidden("ModifySellingPrice", @ViewData["ModifySellingPrice"])
        <input id="_OrderType" type="hidden" value="x" />

        <label id="orderInfo"></label>
        <label class="radio-inline">
            <input type="checkbox" id="autoPrint" />打印
        </label>
        <label class="radio-inline">
            <input type="checkbox" id="tuiHuo" /> 退货
        </label> 

        <hr />
        <div class="form-inline">
            <input type="button" value="保存订单" id="SaveOrder" class="btn btn-success" />&nbsp;&nbsp;&nbsp;&nbsp;
            <div class="form-group">
                <input type="text" id="InputCode" class="form-control text-box single-line" />
            </div>
            &nbsp;&nbsp;&nbsp;<input type="button" value="加载" id="LoadProduct" class="btn btn-info" />
        </div>

        <div id="tableDetail">
            <table class="display">
                <thead>
                    <tr>
                        <th>编码</th>
                        <th>条形码</th>
                        <th>名称</th>
                        <th>单位</th>
                        <th>销售价</th>
                        <th>数量</th>
                        <th>小计</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody></tbody>
                <tfoot><tr><td colspan="6">合计</td><td id="calcSum">0</td><td></td></tr></tfoot>
            </table>
        </div>
    </div>
}

<script src="/Scripts/Erp/defineDataTable.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        InitDataTable();
        $("#tableDetail tbody").empty();

        $("#SaveOrder").click(function () {
            var p = FormatProductList();
            if (p == "") {
                alert("商品列表不能为空");
            }
            else {
                $.post("/Jxc/PosConfirm", {
                    productList: p,
                    flag: ($("#tuiHuo").prop('checked') == true ? 1 : 0)
                }, function (result) {
                    if (result == "failed") {
                        alert('订单提交失败');
                        window.location.reload();
                    }
                    else {
                        $("#orderInfo").text('上一单:' + result + '(' + $("#calcSum").text() + ')');
                         
                        var row = $("#tableDetail").find("tr").length;
                        while (row > 2) {
                            RemoveTableTr(1);
                            row = $("#tableDetail").find("tr").length;
                        };
                        $("#calcSum").text("");

                        if ($("#autoPrint").prop('checked') == true) {
                            window.open("/Jxc/ReportPrint?flag=2&id=-1&str=" + result);
                        }
                        else {
                            alert('订单完成');
                        }
                    }
                });
            }
        });

    });
</script>